﻿using System;
using System.Collections.Generic;
using System.Linq;
using DomainModel;
using Repository.Abstract;
using Services.Abstract;

namespace Services.Concrete
{
    public class TimetableService : Service<Timetable>, ITimetableService
    {
        private readonly ITimetableRepository _timetableRepository;

        public TimetableService(ITimetableRepository timetableRepository)
            : base(timetableRepository)
        {
            _timetableRepository = timetableRepository;
        }

        public List<Timetable> Get(User teacher, int week, int day)
        {
            if (teacher == null)
                throw new ArgumentNullException("teacher");

            if (week != 1 && week != 2)
                return null;

            if (day < 1 || day > 7)
                return null;

            if (!teacher.Roles.Contains(Role.Teacher))
                return null;

            return _timetableRepository.GetTimetablesByTeacherAndWeekAndDay(teacher, week, day).ToList();
        }

        public List<Timetable> Get(Group group, int week = 0, int day = 0)
        {
            if (group == null) 
                throw new ArgumentNullException("group");

            if (week != 1 && week != 2)
                return null;

            if (day < 1 || day > 7)
                return null;

            return _timetableRepository.GetTimetablesByGroupAndWeekAndDay(group, week, day).ToList();
        }

        public List<Timetable> Get(Subgroup subgroup, int week = 0, int day = 0)
        {
            if (subgroup == null)
                throw new ArgumentNullException("subgroup");

            if (week != 1 && week != 2)
                return null;

            if (day < 1 || day > 7)
                return null;

            return _timetableRepository.GetTimetablesBySubgroupAndWeekAndDay(subgroup, week, day).ToList();
        }
    }
}